package com.abso.mp3tunes.locker.ui.views;

import org.eclipse.swt.widgets.Composite;

import com.abso.mp3tunes.locker.ui.viewers.LockerViewer;

/**
 * An abstract base class for panels of the Locker browser view.
 */
public abstract class LockerBrowserViewPanel {

	/** The Locker browser view. */
	private LockerBrowserView lockerBrowserView;

	/** The control contributed by this panel. */
	private Composite control;

	/**
	 * Constructs a new panel.
	 * 
	 * @param parent
	 *            the parent control.
	 * @param lockerBrowserView
	 *            the locker browser view.
	 */
	public LockerBrowserViewPanel(Composite parent,
			LockerBrowserView lockerBrowserView) {
		this.lockerBrowserView = lockerBrowserView;
		this.control = createControl(parent);
	}

	/**
	 * Returns the locker browser view.
	 * 
	 * @return the locker browser view.
	 */
	protected final LockerBrowserView getLockerBrowserView() {
		return lockerBrowserView;
	}

	/**
	 * Creates the control contributed by this panel.
	 * 
	 * @param parent
	 *            the parent control.
	 * @return the created control.
	 */
	protected abstract Composite createControl(Composite parent);

	/**
	 * Returns the Locker viewer associated with this panel.
	 * 
	 * @return the Locker viewer.
	 */
	protected abstract LockerViewer getLockerViewer();

	/**
	 * Returns the contributed control.
	 * 
	 * @return the control.
	 */
	public final Composite getControl() {
		return control;
	}

	/** Collapses all the tree nodes. */
	public void collapseAll() {
		try {
			getLockerViewer().getTree().setRedraw(false);
			getLockerViewer().collapseAll();
		} finally {
			getLockerViewer().getTree().setRedraw(true);
		}
	}

}
